package test1014;

import java.util.Scanner;

public class Calculator {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("请输入第一个操作数: ");
        double operand1 = scanner.nextDouble();

        System.out.print("请输入第二个操作数: ");
        double operand2 = scanner.nextDouble();

        System.out.print("请输入运算符 (+, -, *, /): ");
        String operator = scanner.next();

        double result;

        switch (operator) {
            case "+":
                result = operand1 + operand2;
                System.out.println("计算结果: " + result);
                break;
            case "-":
                result = operand1 - operand2;
                System.out.println("计算结果: " + result);
                break;
            case "*":
                result = operand1 * operand2;
                System.out.println("计算结果: " + result);
                break;
            case "/":
                if (operand2 != 0) {
                    result = operand1 / operand2;
                    System.out.println("计算结果: " + result);
                } else {
                    System.out.println("错误：除数不能为零。");
                }
                break;
            default:
                System.out.println("错误：无效的运算符。");
                break;
        }
    }
}